package com.qclix.inv;

import java.io.Serializable;
import java.util.Date;

/**
 * Standard day
 */
public class WeekDay implements Cloneable, Serializable, Comparable<WeekDay> {
    private static final long serialVersionUID = 1L;

    private long id;
    private Date date;
    private boolean weekend;
    private boolean holiday;
    private int workedStdHours;
    private int workedOverTimeHours;
    private boolean partOfInvoice;
    private Timesheet timesheet;

    public WeekDay() {
        partOfInvoice = false;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public boolean isWeekend() {
        return weekend;
    }

    public void setWeekend(boolean weekend) {
        this.weekend = weekend;
    }

    public boolean isHoliday() {
        return holiday;
    }

    public void setHoliday(boolean holiday) {
        this.holiday = holiday;
    }

    public int getWorkedStdHours() {
        return workedStdHours;
    }

    public void setWorkedStdHours(int workedStdHours) {
        this.workedStdHours = workedStdHours;
    }

    public int getWorkedOverTimeHours() {
        return workedOverTimeHours;
    }

    public void setWorkedOverTimeHours(int workedOverTimeHours) {
        this.workedOverTimeHours = workedOverTimeHours;
    }

    public boolean isPartOfInvoice() {
        return partOfInvoice;
    }

    public void setPartOfInvoice(boolean partOfInvoice) {
        this.partOfInvoice = partOfInvoice;
    }

    public Timesheet getTimesheet() {
        return timesheet;
    }

    public void setTimesheet(Timesheet timesheet) {
        this.timesheet = timesheet;
    }

    @Override
    public int compareTo(WeekDay o) {
        return date.compareTo(o.getDate());
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        super.clone();
        WeekDay clone = new WeekDay();
        clone.setDate(new Date(date.getTime()));
        clone.setHoliday(holiday);
        clone.setWeekend(weekend);
        clone.setWorkedStdHours(workedStdHours);
        clone.setWorkedOverTimeHours(workedOverTimeHours);
        clone.setPartOfInvoice(partOfInvoice);
        clone.setTimesheet(timesheet);
        return clone;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("WeekDay [ date = ").append(date);
        sb.append(", holiday = ").append(holiday);
        sb.append(", weekend = ").append(weekend);
        sb.append(", worked std hours = ").append(workedStdHours);
        sb.append(", worked overtime = ").append(workedOverTimeHours);
        sb.append(", part  of invoice = ").append(partOfInvoice);
        if (timesheet != null) {
            sb.append(", associated to timesheet ").append(timesheet.getId());
        } else {
            sb.append(", no associated timesheet");
        }
        sb.append(" ]");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        WeekDay weekDay = (WeekDay) o;

        if (date != null ? !date.equals(weekDay.date) : weekDay.date != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return date != null ? date.hashCode() : 0;
    }
}
